package com.yoomiito.app.ui.fragment

import cn.droidlover.xdroidmvp.net.ApiException
import cn.droidlover.xdroidmvp.net.ApiSubscriber
import cn.droidlover.xdroidmvp.net.XApi
import com.yoomiito.app.base.AppConfig
import com.yoomiito.app.base.BaseActPresenter
import com.yoomiito.app.base.BasePresenter
import com.yoomiito.app.model.LatLng
import com.yoomiito.app.model.oil.OilBannerData
import com.yoomiito.app.model.oil.OilStationData
import com.yoomiito.app.model.oil.OilStationDetailData
import com.yoomiito.app.net.YmApi
import com.yoomiito.app.showToast
import com.yoomiito.app.utils.GPSConverterUtils
import com.yoomiito.app.utils.L

class GasStationListPresenter_1(appConfig: AppConfig) :BasePresenter<GasStationListFragment>(appConfig){

    fun list(oilNum:Int,latLng: LatLng,page:Int){
        val gps = GPSConverterUtils.gcj_To_Gps84(latLng.lat, latLng.lng)
        YmApi.getYmService()
                .oilStationList(oilNum,gps.lon,gps.lat,page,"","")
                .compose(v.bindToLifecycle())
                .compose(XApi.getApiTransformerData())
                .compose(XApi.getScheduler())
                .subscribe(object : ApiSubscriber<List<OilStationData>>(){
                    override fun onSuccess(t: List<OilStationData>?) {
                        v.setData(t as MutableList<OilStationData>?)
                    }

                    override fun onFail(error: ApiException?) {
                            v.showErrorView()
                        v.dismissLoading()
                    }

                })
    }

//    fun banner(){
//        YmApi.getYmService()
//                .oilBanner()
//                .compose(v.bindToLifecycle())
//                .compose(XApi.getApiTransformerData())
//                .compose(XApi.getScheduler())
//                .subscribe(object :ApiSubscriber<OilBannerData>(){
//                    override fun onSuccess(t: OilBannerData?) {
//                        v.setBanner(t)
//                    }
//
//                    override fun onFail(error: ApiException?) {
//                        v.dismissLoading()
//                    }
//
//                })
//    }
}